package com.bot.nft.module.dc.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bot.nft.module.dc.domain.DcFlowLog;
import com.bot.nft.module.dc.domain.bo.DcFlowLogBo;
import com.bot.nft.module.dc.domain.vo.CertFlowVo;
import com.bot.nft.module.dc.domain.vo.DcFlowLogVo;
import com.bot.nft.module.dc.mapper.DcFlowLogMapper;
import com.bot.nft.module.dc.service.IDcFlowLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author RenXiaoZheng
 * @since 2024-01-24
 */
@Service
public class DcFlowLogServiceImpl extends ServiceImpl<DcFlowLogMapper, DcFlowLog> implements IDcFlowLogService {

    //日志
    private static final Log log = LogFactory.get();

    //mapper
    @Resource
    private DcFlowLogMapper dcFlowMapper;

    /**
     * 查询藏品流转记录
     *
     * @param inPhone  藏品名称关键字
     * @param outPhone
     * @param name     流转时间
     * @param pageNo   当前第几页
     * @param pageSize 每页显示多少条数据
     * @return
     */
    @Override
    public Page<DcFlowLogVo> queryDcFlowLog(String inPhone, String outPhone, String name, Integer pageNo, Integer pageSize) {
        log.info("开始根据关键字{}流转方式{}分页查询流转方式", inPhone, outPhone, name);
        //分页查询流转记录
        Page<DcFlowLogVo> page = new Page<>(pageNo, pageSize);
        Page<DcFlowLogVo> dcFlowLogVos = dcFlowMapper.selectDcFlow(inPhone, outPhone, name, page);
        log.info("查询藏品信息结束共{}", dcFlowLogVos.getSize());
        return dcFlowLogVos;
    }

    /**
     * 查看藏品流转记录
     *
     * @param id 藏品流传记录信息标识
     * @return
     */
    @Override
    public List<DcFlowLogVo> getDcFlowLog(String id) {
        QueryWrapper<DcFlowLog> dcFlowLogVoQueryWrapper = new QueryWrapper<>();
        dcFlowLogVoQueryWrapper.lambda().eq(DcFlowLog::getCertId,id);
        log.info("开始根据流转记录Id{}查看流转记录信息详情", id);
        List<DcFlowLogVo> dcFlowLogVos = dcFlowMapper.selectVoList(dcFlowLogVoQueryWrapper);
        log.info("结束流转记录{}信息详情", id);
        //查询流转信息详情
        return dcFlowLogVos;
    }

    @Override
    public List<CertFlowVo> getFlowLogByCertId(String certId) {
        List<CertFlowVo> flowLogVoList = dcFlowMapper.getFlowLogByCertId(certId);
        return flowLogVoList;
    }

    /**
     * 添加藏品流转记录
     *
     * @param dcFlowLogBo
     * @return
     */
    @Override
    public Boolean addFlowLog(DcFlowLogBo dcFlowLogBo) {
        //Bo转entity
        //新建entti
        DcFlowLog dcFlowLog = BeanUtil.toBean(dcFlowLogBo, DcFlowLog.class);
        //调用sql
        int insert = dcFlowMapper.insert(dcFlowLog);
        return insert > 0;
    }

}
